#include<iostream>
#include<vector>
#include<unordered_set>
#include<algorithm>
using namespace std;

class Solution {
public:
	vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
		unordered_set<int> set1, set2;
		if (nums1.size() > nums2.size()) {
			vector<int> tmp = nums2;
			nums2 = nums1;
			nums1 = tmp;
		}
		for (auto &num : nums1) {
			set1.insert(num);
		}
		for (auto &num : nums2) {
			set2.insert(num);
		}
		vector<int> result;
		for (auto &num : set1) {
			if (set2.count(num)) {
				result.push_back(num);
			}
		}
		return result;
	}

};

void main() {
	vector<int> nums1 = { 1,2,2,1 };
	vector<int> nums2 = { 2 ,2};
	Solution s;
	s.intersection(nums1, nums2);
}